<?php 
require_once("model/loginBD.php");
function search_user_db($suser) {
	$query = "SELECT id_user, mail, civilite, nom, prenom FROM user
				WHERE id_user LIKE (\"%$suser%\")
				OR mail LIKE (\"%$suser%\")
				OR nom LIKE (\"%$suser%\")
				OR prenom LIKE (\"%$suser%\")"; 
								 
	logIn();
	$result = mysql_query($query) or die('Erreur SQL !'.$query.'<br>'.mysql_error());	
	logOut();
	$total = mysql_num_rows($result);
	if($total) {
		$i = 0;
		while($row = mysql_fetch_array($result)) {
			$tab['id_user'][$i] = $row['id_user'];
			$tab['mail'][$i] = $row['mail'];
			$tab['civilite'][$i] = $row['civilite'];
			$tab['nom'][$i] = $row['nom'];
			$tab['prenom'][$i] = $row['prenom'];
			++$i;
		}
	}
	if( mysql_num_rows($result) > 0) return $tab;	else return 0;
}

function search_category_db($scategory) {
	$query = "SELECT id_categ, name_categ, comment_categ FROM category
				WHERE id_categ LIKE (\"%$scategory%\")
				OR name_categ LIKE (\"%$scategory%\")
				OR comment_categ LIKE (\"%$scategory%\")";
								 
	logIn();
	$result = mysql_query($query) or die('Erreur SQL !'.$query.'<br>'.mysql_error());	
	logOut();
	$total = mysql_num_rows($result);
	if($total) {
		$i = 0;
		while($row = mysql_fetch_array($result)) {
			$tab['id_categ'][$i] = $row['id_categ'];
			$tab['name_categ'][$i] = $row['name_categ'];
			$tab['comment_categ'][$i] = $row['comment_categ'];
			++$i;
		}
	}
	if( mysql_num_rows($result) > 0) return $tab;	else return 0;
}

function search_tweet_db($stweet) {
	$query = "SELECT id_tweet, id_user, id_categ, text_tweet, date_tweet FROM tweet
				WHERE id_tweet LIKE (\"%$stweet%\")
				OR id_user LIKE (\"%$stweet%\")
				OR id_categ LIKE (\"%$stweet%\")
				OR text_tweet LIKE (\"%$stweet%\")"; 
								 
	logIn();
	$result = mysql_query($query) or die('Erreur SQL !'.$query.'<br>'.mysql_error());	
	logOut();
	$total = mysql_num_rows($result);
	if($total) {
		$i = 0;
		while($row = mysql_fetch_array($result)) {
			$tab['id_tweet'][$i] = $row['id_tweet'];
			$tab['id_user_tweet'][$i] = $row['id_user'];
			$tab['id_categ_tweet'][$i] = $row['id_categ'];
			$tab['text_tweet'][$i] = $row['text_tweet'];
			$tab['date_tweet'][$i] = $row['date_tweet'];
			++$i;
		}
	}
	if( mysql_num_rows($result) > 0) return $tab;	else return 0;
}

?>